<?php

class spDialog extends spDiv
{
	static public function create( $param )
	{
		$param = array_merge(
			array(
				"title"				=> "",
				"roundedCorners"	=> true,	
				"bedit" 			=> false,
				"bdelete" 			=> false,
				"btrash"			=> false,
				"bsave"				=> false,	// save when editing an object
				"bsavenew"			=> false,	// save when a new object
				"data-id"			=> "",		// database id
				"data-database"		=> "",		// database class name
				"data-name"			=> ""		// database name
			),
			$param
		);
	
		$classDialog = "spDialogStatic";
		$classTitle = "spTitle";
		
		if ( $param["roundedCorners"] )
		{
			$classDialog.= " spRounded";
			$classTitle	 .= " spTitleBlack";
		}
	
		$container = new spDiv(array(
			"class" => $classDialog
		));
		$title = new spDiv(array(
			"class"		=> $classTitle,
			"content" 	=> $param["title"]
		));
		$container->addChild( $title );

		if ( $param["btrash"] )
		{
			$trash = new spAnchor(array(
				"class" 	=> "formTrash",
				"href" 		=> "",
				"content" 	=> "(trash)",
				"attr"		=> array(
					"data-id" 		=> $param["data-id"],
					"data-database" => $param["data-database"],
					"data-name"		=> $param["data-name"]
				)
			));
			$container->addChild( $trash );
		}

		if ( $param["bdelete"] )
		{
			$delete = new spAnchor(array(
				"class" 	=> "formDelete",
				"href" 		=> "",
				"content" 	=> "(delete)",
				"attr"		=> array(
					"data-id" 		=> $param["data-id"],
					"data-database" => $param["data-database"],
					"data-name"		=> $param["data-name"]
				)
			));
			$container->addChild( $delete );
		}
		
		if ( $param["bedit"] )
		{
			$edit = new spAnchor(array(
				"class" 	=> "formEdit",
				"href" 		=> "",
				"content" 	=> "(edit)",
				"attr"		=> array(
					"data-id" 		=> $param["data-id"],
					"data-database" => $param["data-database"],
					"data-name"		=> $param["data-name"]
				)
			));
			$container->addChild( $edit );	
		}

		if ( $param["bsave"] )
		{
			$save = new spAnchor(array(
				"class" 	=> "formSave",
				"href" 		=> "",
				"content" 	=> "(save)",
				"attr"		=> array(
					"data-id" 		=> $param["data-id"],
					"data-database" => $param["data-database"],
					"data-name"		=> $param["data-name"]
				)
			));
			$container->addChild( $save );	
		}

		if ( $param["bsavenew"] )
		{
			$save = new spAnchor(array(
				"class" 	=> "formSaveNew",
				"href" 		=> "",
				"content" 	=> "(save)",
				"attr"		=> array(
					"data-id" 		=> $param["data-id"],
					"data-database" => $param["data-database"],
					"data-name"		=> $param["data-name"]
				)
			));
			$container->addChild( $save );	
		}

		$container->addChild( new spClearBoth );
		
		return $container;
	}
	
	static public function createFieldSet( $title )
	{
		$fs = new spFieldSet(array(
			"class" => "spFieldSet"
		));
		$fs->addChild( new spLegend(array(
			"content" => $title
		)));
				
		return $fs;
	}
}

?>